<?php
/**
 * Created by PhpStorm.
 * User: xiemi
 * Date: 2020/3/26
 * Time: 20:47
 */

namespace darksun;


class App extends Container
{
    private $handleList = [
        ExceptionHandle::class,
        Request::class,
        Route::class
    ];

    private $appDebug = false;

    private $beginTime;

    private $beginMem;

    private $namespace = 'darksun';

    private $responseData;

    protected $bindings = [
        'app' => App::class,
        'config' => Config::class,
        'log' => Log::class,
        'request' => Request::class,
        'route' => Route::class
    ];


    public function __construct()
    {
        $this->beginTime = microtime(true);
        $this->beginMem  = memory_get_usage();
        static::setInstance($this);
        $this->bind('app', $this);
        $this->bind('darksun\Container', $this);
    }

    public function addHandle($handle){
        $handle = is_string($handle)?$handle:get_class($handle);
        $this->handleList[] = $handle;
    }

    public function boot(){
        foreach($this->handleList as $handle)
        {
            $this->make($handle)->bootService($this);
        }
    }

    public function __get($name)
    {
        return $this->get($name);
    }

    public function __set($name, $value)
    {
        $this->bind($name, $value);
    }


}